/**
 * 百度地图Util
 */
var map ;
var mapUtil = {
		init:function(cityName,level){
			// 百度地图API功能
			map = new BMap.Map("map");    // 创建Map实例
			map.centerAndZoom(gdv(cityName,'南京'),gdv(level,12));  // 初始化地图,设置中心点坐标和地图级别
			//添加地图类型控件
			map.addControl(new BMap.MapTypeControl({
				mapTypes:[
			        BMAP_NORMAL_MAP,
			        BMAP_HYBRID_MAP
			    ]}));	  
			map.enableScrollWheelZoom(true);     //开启鼠标滚轮缩放
		},
		autoLocation:function(type,lonSelector,latSelector){
			if(gdv(type,"iframe") == "iframe" ){
				var geolocation = new BMap.Geolocation();
				geolocation.getCurrentPosition(function(r){
					if(this.getStatus() == BMAP_STATUS_SUCCESS){
						var mk = new BMap.Marker(r.point);
						map.addOverlay(mk);
						map.panTo(r.point);
//				 		console.log('您的位置：'+r.point.lng+','+r.point.lat);
						$(lonSelector).val(r.point.lng);
						$(latSelector).val(r.point.lat);
					}
					else {
						console.log('failed'+this.getStatus());
					}        
				},{enableHighAccuracy: true})
			}
		}
}



map.addEventListener("click", showInfo);



function showInfo(e){
	theLocation(e.point.lng , e.point.lat);
	gic("lon").val(e.point.lng);
	gic("lat").val(e.point.lat);
}


function theLocation(lon,lat){
	map.clearOverlays(); 
	var new_point = new BMap.Point(lon,lat);
	var marker = new BMap.Marker(new_point); 
	map.addOverlay(marker);
	map.panTo(new_point);      
}

